﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace RzCorportativo.Views
{
    public partial class Experiencia : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (this.IsPostBack)
                return;
            this.NomeCargoExperiencia.Attributes.Add("url", this.ResolveUrl("~/Views/Cadastros/Curriculo.aspx/ListarCargos"));
            var curriculo = Lib.Curriculo.Listar(new Lib.Curriculo()
            {
                UsuarioId = (AppSession.Login.Usuario ?? new Lib.Usuario()).UsuarioId
            }).FirstOrDefault();
            var lista = Lib.Experiencia.Listar(new Lib.Experiencia()
            {
                CurriculoId = (curriculo ?? new Lib.Curriculo()).CurriculoId
            });
            foreach (var item in lista)
            {
                var row = new System.Web.UI.HtmlControls.HtmlTableRow();
                row.Cells.Add(new System.Web.UI.HtmlControls.HtmlTableCell()
                {
                    InnerText = (item.Empresa ?? string.Empty).ToUpper()
                });
                row.Cells.Add(new System.Web.UI.HtmlControls.HtmlTableCell()
                {
                    InnerText = ((item.Cargo ?? new Lib.Cargo()).Nome ?? string.Empty).ToUpper()
                });
                row.Cells.Add(new System.Web.UI.HtmlControls.HtmlTableCell()
                {
                    InnerText = item.DataAdmissao.ToString("dd/MM/yyyy")
                });
                row.Cells.Add(new System.Web.UI.HtmlControls.HtmlTableCell()
                {
                    InnerText = !item.DataDemissao.HasValue ? string.Empty : item.DataDemissao.Value.ToString("dd/MM/yyyy")
                });
                row.Cells.Add(new System.Web.UI.HtmlControls.HtmlTableCell()
                {
                    InnerHtml = "<input type='button' id='btnRemoveExperiencia" + item.ExperienciaId.ToString() +
                    "' onclick='RemoveExperiencia(" + item.ExperienciaId.ToString() +
                    ", this)' class='btn btn-danger' value='remover'/>"
                });
                row.Attributes.Add("experiencia", item.ExperienciaId.ToString());
                this.gridExperiencia.Rows.Add(row);
            }
        }
    }
}